<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <!--导入猫头鹰样式-->
    <link rel="stylesheet" th:href="@{/css/login.css}">
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!--密码框的焦点-->
    <script type="text/javascript">
        $(function(){
            $('#password').focus(function(){
                // 密码框获得焦点，追加样式.password
                $('#owl').addClass('password');
            }).blur(function(){
                // 密码框失去焦点，移除样式.password
                $('#owl').removeClass('password');
            })
        })
    </script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css"
          th:href="@{/bootstrap/css/bootstrap.min.css}"/>
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}">
    </script>
    <!-- jquery-validator -->
    <script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- md5.js -->
    <script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>
<form name="loginForm" id="loginForm" method="post" style="width: 50%;margin: 0 auto">
    <div class="form-group">
        <div class="login-box">
            <p></p>
        </div>
        <div class="login-box">
            <div class="owl" id="owl">
                <div class="hand"></div>
                <div class="hand hand-r"></div>
                <div class="arms">
                    <div class="arm"></div>
                    <div class="arm arm-r"></div>
                </div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入手机号码</label>
        </div>
        <div class="row">

            <div class="col-md-5">
                <input id="mobile" name="mobile" class="form-control"
                       type="text" placeholder="手机号码" required="true"
                       minlength="11" maxlength="11"/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入密码</label>
        </div>

        <div class="row">

            <div class="col-md-5">
                <input id="password" name="password" class="form-control"
                       type="password" placeholder="密码"
                       required="true" minlength="6" maxlength="16"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <div class="col-md-5">
                <button class="btn btn-primary btn-block" type="reset"
                        onclick="reset()">重置
                </button>
            </div>
        </div>
        <div class="row">
            <div class="col-md-5">
                <button class="btn btn-primary btn-block" type="submit"
                        onclick="login()">登录
                </button>
            </div>
        </div>
    </div>
    <p>
        没有账号？<a href="/register/toregister">请注册</a>
    </p>
</form>
</body>
<script>
    function login() {
        // var a=document.getElementById("mobile").value;
        /*登录校验*/
        $("#loginForm").validate({
            submitHandler: function (form) {
                /*校验成功，调用doLogin*/
                doLogin();
            }
        });
    }

    function doLogin() {
        g_showLoading();/*加载图标转圈圈*/
        var inputPass = $("#password").val();/*拿明文密码*/
        var salt = g_passsword_salt;/*拿salt*/
        var str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(6) + salt.charAt(3);/*一次md5加密*/
        var password = md5(str);
        $.ajax({
            url: "/login/doLogin",/*调用后端接口*/
            type: "POST",
            data: {
                mobile: $("#mobile").val(),
                password: password
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 200) {/*状态码*/
                    layer.msg("成功");
                    var a=document.getElementById("mobile").value;
                    var b="13869623321";
                    if(a==b){
                        window.location.href = "/grounding/togrounding";
                    }
                    else {
                        window.location.href = "/goods/toList";
                    }
                    // window.location.href = "/goods/toList";
                } else {
                    layer.msg(data.message);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
</script>
</html>